<?php 

require_once  __DIR__ . '/includes/authenticate.php';
include_once __DIR__ . '/db_bb_connect.php';

require_once __DIR__ . '/includes/BasketbalFunctions.php';
$basketbalfunctions = new BasketbalFunctions();

if (isset($_POST['article_ID']))  { 

$setarticleID = $_POST['article_ID'];

$username = $_SESSION['username'];

$user_key = $_SESSION['user_key'];

$sql = "INSERT INTO clicked_items (user_key, clicked_item) VALUES ( '$user_key' , 'view_article_$setarticleID' )";

$db->query($sql);

$type = $basketbalfunctions->GetUserLoginType();

	?>     
 <?php   

  $sql = "SELECT title, text FROM articles WHERE ID = '$setarticleID'";
  $result = $db->query($sql);
  $row = $result->fetch_assoc();
  $settitle = $row['title'];
  $settext = $row['text']; 

?>
<button class="btn btn-default btn-sm backtooverview">Back to Overview</button>

<h2><?= $settitle?></h2>

<?= $settext?>

<script type="text/javascript">
  
    $(".backtooverview").on("click", function(e){
    e.preventDefault(); 
    $.ajax({
        type: "POST",
          url: "./article_overview_player.php",
          success: function(data) {    
            $("#content").html(data);
          },
          error: function (xhr, status, error) {
            $("#content").html(xhr.responseText);
          }
      });

  });

</script>


<?php }?>